// // Copyright (c) 2009 All Right Reserved // // vl // // 2009-01-01 // Contains ... using System.Diagnostics.Contracts; using System.Text; using System.Xml.Linq; using LargoCommon.Abstract; namespace LargoCommon.Music { /// /// Musical Metric. /// public sealed class MusicalMetric { #region Constructors /// /// Initializes a new instance of the class. /// /// The given beat. /// The given base. public MusicalMetric(byte givenBeat, byte givenBase) { this.MetricBeat = givenBeat; this.MetricBase = givenBase; } /// /// Initializes a new instance of the class. /// /// The element of metric. public MusicalMetric(XElement xmetric) { Contract.Requires(xmetric != null); if (xmetric == null) { return; } this.MetricBeat = XmlSupport.ReadByteAttribute(xmetric.Attribute("Beat")); this.MetricBase = XmlSupport.ReadByteAttribute(xmetric.Attribute("Base")); } #endregion #region Properties - Xml /// /// Gets the get x element. /// /// /// The get x element. /// public XElement GetXElement { get { XElement xsystem = new XElement("Metric", null); xsystem.Add(new XAttribute("Beat", this.MetricBeat)); xsystem.Add(new XAttribute("Base", this.MetricBase)); return xsystem; } } #endregion #region Properties /// /// Gets or sets metric beat. /// /// Property description. public byte MetricBeat { get; set; } /// /// Gets or sets metric base. /// /// Property description. public byte MetricBase { get; set; } /// Gets musical tempo. /// Property description. public byte MetricGround => MusicalProperties.GetMetricGround(this.MetricBase); /// /// Gets the metric value. /// /// Property description. public string MetricValue => MusicalProperties.GetMetricValue(this.MetricBeat, this.MetricGround); #endregion #region Public methods /// /// Resets this instance. /// public void Reset() { this.MetricBeat = 0; this.MetricBase = 0; } /// /// Clones this instance. /// /// Returns value. public object Clone() { var m = new MusicalMetric(this.MetricBeat, this.MetricBase); return m; } #endregion #region String representation /// String representation of the object. /// Returns value. public override string ToString() { var s = new StringBuilder(); s.AppendFormat("{0}/{1}", this.MetricBeat, this.MetricGround); //// Metric return s.ToString(); } #endregion } }